package cn.edu.cuit.aumalls.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.edu.cuit.aumalls.entity.Goods;
import cn.edu.cuit.aumalls.service.FindGoodsService;
import en.edu.cuit.aumalls.mapper.FindGoodsMapper;
import en.edu.cuit.aumalls.mapper.GoodsMapper;
import en.edu.cuit.aumalls.mapper.GoodsTypeMapper;

@Service("findGoodsService")
public class FindGoodsServiceImpl implements FindGoodsService {
	@Autowired
	private FindGoodsMapper findGoodsMapper;

	@Autowired
	private GoodsTypeMapper goodsTypeMapper;
	
	private PageInfo<Goods> pageInfols;
	
	@Override
	public PageInfo<Goods> findGoodsByname(int pageNum, int pageSize, String goods_name) {
		PageHelper.startPage(pageNum, pageSize);
		
		List<Goods> list = findGoodsMapper.findGoodsByName(goods_name);
		
		pageInfols = new PageInfo<Goods>(list);
		return pageInfols;
	}

	@Override
	public PageInfo<Goods> findGoodsByTypename(int pageNum, int pageSize, String goods_Typename) {
		
		
		int goodsTypeID = goodsTypeMapper.findTypeID(goods_Typename);
		
		PageHelper.startPage(pageNum, pageSize);
		List<Goods> list = findGoodsMapper.findGoodsBytype(goodsTypeID);
		
		PageInfo<Goods> pageInfols = new PageInfo<Goods>(list);
		return pageInfols;
	}

	@Override
	public PageInfo<Goods> findGoodsByPrice(int pageNum, int pageSize, float startPrice, float endPrice) {

		PageHelper.startPage(pageNum, pageSize);
		List<Goods> list = findGoodsMapper.findGoodsByPrice(startPrice, endPrice);
		
		
		pageInfols = new PageInfo<Goods>(list);
		return pageInfols;
	}

	@Override
	public PageInfo<Goods> findGoodsByEndPrice(int pageNum, int pageSize, float endPrice) {
		PageHelper.startPage(pageNum, pageSize);
		List<Goods> list = findGoodsMapper.findGoodsByEndPrice(endPrice);
		
		
		pageInfols = new PageInfo<Goods>(list);
		return pageInfols;
	}

	@Override
	public PageInfo<Goods> findGoodsByStartPrice(int pageNum, int pageSize, float startPrice) {
		PageHelper.startPage(pageNum, pageSize);
		
		List<Goods> list = findGoodsMapper.findGoodsByStartPrice(startPrice);
		
		pageInfols = new PageInfo<Goods>(list);
		return pageInfols;
	}


}
